package com.company;

import java.util.Arrays;

public class Main {
    public static int minDistance(String word1,String word2){
        int m = word1.length(),
                n = word2.length();
        int [][] result = new int[m+1][n+1];

        for(int i=0;i<n+1;i++)result[0][i] = i;
        for (int i=0;i<m+1;i++)result[i][0] = i;

        for (int i=1;i<m+1;i++){
            for(int j=1;j<n+1;j++){
                if(word1.charAt(i-1)==word2.charAt(j-1)){
                    result[i][j] = 1 + Math.min(Math.min(result[i][j-1],result[i-1][j]),result[i-1][j-1]-1);
                }else{
                    result[i][j] = 1 + Math.min(Math.min(result[i][j-1],result[i-1][j]),result[i-1][j-1]);
                }
            }
        }
//        System.out.println(Arrays.deepToString(result));
        return result[m][n];
    }
    public static void main(String[] args) {
	// write your code here
        System.out.println(minDistance("intention","execution"));
    }
}
